#!/bin/env ruby
# encoding: utf-8

def user_signs_in
  text_field(name: 'j_username').wait_until_present
  text_field(name: 'j_username').set 'autosam55@yandex.ru'
  text_field(name: 'j_password').set '321654987'
  button(text: 'OK').click
  a(href: '/en/us/profile').should be_present  
  (browser.url.include? '/en/login-page').should be_falsey
end

def sign_in (usernameM, userpasswordM)
  text_field(name: 'j_username').wait_until_present
  text_field(name: 'j_username').set usernameM
  text_field(name: 'j_password').set userpasswordM
  button(text: 'OK').click
  a(href: '/en/us/profile').should be_present  
  (browser.url.include? '/en/login-page').should be_falsey
end

def email_template
  a(href: '#collapseFour').click
  a(href: '/en/us/admin/welcome-email-settings-list').wait_until_present
  a(href: '/en/us/admin/welcome-email-settings-list').click
  a(href: '#index1').click
  (browser.text.include? 'Employee engagement and leadership development').should be_truthy
  a(href: '#index2').click
  (browser.text.include? 'Benefits').should be_truthy
  a(href: '#index3').click
  (browser.text.include? 'How it works').should be_truthy
  a(href: '#index4').click
  (browser.text.include? 'Sign up email').should be_truthy
  a(href: '#index0').click
  (browser.text.include? 'Introduction to Pulse').should be_truthy
  (browser.url.include? '/en/us/admin/welcome-email-settings-list').should be_truthy # need check URL in browsers
  (browser.text.include? 'Introduction to Pulse').should be_truthy # need check text in browsers
end

def user_logout
	form(id: 'logout-form').submit
end

def profile_edit
  a(href: '/en/us/profile').click
  text_field(id: 'firstName').should be_present
  text_field(id: 'middleName').should be_present
  text_field(id: 'lastName').should be_present
  text_field(id: 'lastName').should be_present
  text_field(id: 'oldPassword').should be_present
  text_field(id: 'newPassword').should be_present
  button(name: 'submit').should be_present
  text_field(id: 'firstName').clear
  button(name: 'submit').click
  span(class: 'help-block', text: 'First name cannot be empty')
  text_field(id: 'lastName').clear
  button(name: 'submit').click
  span(class: 'help-block', text: 'Last name cannot be empty')
  text_field(id: 'firstName').set 'User'
  text_field(id: 'middleName').set 'User1'
  text_field(id: 'lastName').set 'User2'
  button(name: 'submit').click
end

def check_login_page
  text_field(name: 'j_username').should be_present
  text_field(name: 'j_password').should be_present
  button(text: 'OK').should be_present
  label(class: 'checkbox', text: 'Remember me').checkbox.should be_present
  #STDERR.puts (browser.checkbox).type
  a(href: '/en/us/sign-up', text: 'Sign up').should be_present
  a(href: '/en/us/reset-password', text: 'Forgot password?').should be_present
end

def str(len)
  ustr='a'
  len.times{|i| ustr+='a'}
  return ustr      
end